/**
 * 显示基类
 */
namespace Display {
    export class Manager extends Singleton {

        constructor() {
            super();
        }
        get stage() {
            return egret.MainContext.instance.stage;
        }
        get Scene() {
            return Frame.Game.Scene;
        }
        get StageManager(): StageManager {
            return StageManager.instance();
        }
        get EuiView() {
            return EuiView;
        }
        get FullScreenEuiView(){
            return FullScreenEuiView;
        }
        get Layer() {
            return Layer;
        }

    }
    /**
     * eui显示组件
     */
    class EuiView extends MVC.View {
        constructor($skinName) {
            super($skinName);
        }
    }
    class FullScreenEuiView extends MVC.View {
        constructor($skinName) {
            super($skinName);
            this.percentHeight = 100;
            this.percentWidth = 100;
        }
    }

    class StageManager extends Singleton {
        private _designWidth: number = 1136;
        private _designHeight: number = 640;
        stageScale: number;

        constructor() {
            super();
            this.init();
        }
        private init() {
            //stage分辨率跟随设备分辨率调整
            this.stageResize();
        }
        //最佳运行分辨率
        setContentSize($width, $height) {
            this.orientation = ($width / $height > 1) ? "landscape" : "portrait";
            this.scaleMode = ($width / $height > 1) ? "fixedWidth" : "fixedHeight";
            this._designWidth = $width;
            this._designHeight = $height;
        }
        /**
         * 指定此对象的子项以及子孙项是否接收鼠标/触摸事件
         * @param value
         */
        set touchChildren(value: boolean) {
            Frame.Display.stage.touchChildren = value;
        }

        /**
         * 设置同时可触发几个点击事件，默认为2
         * @param value
         */
        set maxTouches(value: number) {
            Frame.Display.stage.maxTouches = value;
        }

        /**
         * 设置帧频
         * @param value
         */
        set frameRate(value: number) {
            Frame.Display.stage.frameRate = value;
        }

        /**
         * 设置适配方式
         * @param value
         */
        set scaleMode(value: string) {
            Frame.Display.stage.scaleMode = value;
        }
        /**
         * 设置旋转方式
         */
        set orientation($value) {
            Frame.Display.stage.orientation = $value;
        }

        private stageResize() {
            let _stage = Frame.Display.stage;
            _stage.removeEventListener(egret.Event.RESIZE, this.stageResize, this);
            let designWidth: number = this._designWidth;
            let designHeight: number = this._designHeight;
            let clientWidth: number = window.innerWidth;
            let clientHeight: number = window.innerHeight;
            let a: number = clientWidth / clientHeight;
            let b: number = designWidth / designHeight;
            let c: number = a / b;
            if (a > b) {
                designWidth = Math.floor(designWidth * c);
                designHeight = Math.floor(designHeight * c);
            }

            _stage.addEventListener(egret.Event.RESIZE, this.stageResize, this);
        }
    }
    //全屏显示容器
    class FullScreenLayer extends eui.UILayer {
        public constructor() {
            super();

            this.percentWidth = 100;
            this.percentHeight = 100;

            this.touchEnabled = false;
        }
    }
    class Layer {
        //游戏背景
        static background: FullScreenLayer = new FullScreenLayer();
        //游戏内容
        static gameContent: FullScreenLayer = new FullScreenLayer();
        //游戏UI 
        static UI: FullScreenLayer = new FullScreenLayer();
    }
}
